package com.easybuy.sys.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easybuy.sys.model.SysAddress;
import com.easybuy.sys.model.SysUser;
import com.easybuy.sys.service.SysAddressService;
import org.jcp.xml.dsig.internal.dom.ApacheOctetStreamData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author SR.Y
 * @since 2020-12-05
 */
@RestController
@RequestMapping("/model/sysAddress")
public class SysAddressController {

    @Autowired
    private SysAddressService sysAddressService;

    /**
     * 创建地址
     *
     * @param address
     * @return
     */
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public boolean create(@RequestBody SysAddress address) {
        return sysAddressService.creat(address);
    }

    /**
     * 修改地址
     */
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public boolean update(@PathVariable Integer id, @RequestBody SysAddress address) {
        address.setId(id);
        return sysAddressService.update(address);
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public boolean delete(@RequestParam("idList")List<Integer> idList) {
        return sysAddressService.delete(idList);
    }

    /**
     * 条件查询
     *
     * @param address
     * @param pageSize
     * @param pageNum
     * @return
     */
    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ResponseBody
    public Page<SysAddress> list(@RequestBody SysAddress address,
                                 @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return sysAddressService.list(address, pageSize, pageNum);
    }

    /**
     * 全部查询
     *
     * @param pageSize
     * @param pageNum
     * @return
     */
    @RequestMapping(value = "list", method = RequestMethod.GET)
    @ResponseBody
    public Page<SysAddress> list(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return sysAddressService.list(new SysAddress(), pageSize, pageNum);
    }

    @RequestMapping(value = "/get/{id}",method = RequestMethod.POST)
    @ResponseBody
    public SysAddress getOneById(@RequestParam Integer id) {
        return sysAddressService.getOneById(id);
    }
}

